package GUImk2;

import java.awt.CardLayout;
import java.awt.Container;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;



public class SidePanel extends Container {
	
	/**
	 * Allows serialization.
	 */
	private static final long serialVersionUID = 5564406377170362856L;
	
	private Container user_buttons;
	private Container author_buttons;
	private Container reviewer_buttons;
	private Container subprogram_buttons;
	private Container program_buttons;
	
	private CardLayout my_layout;
	
	private final FullFrame my_frame;	
	
	protected static final String[] BUTTON_ROLES = {"user", "author", "reviewer", "subprogram", "program"};
	
	protected SidePanel(final FullFrame frame) {
		super();
		my_frame = frame;
		my_layout = new CardLayout(10,10);
		mapButtons();
		this.setLayout(my_layout);
		this.add(user_buttons, SidePanel.BUTTON_ROLES[0]);
		this.add(author_buttons, SidePanel.BUTTON_ROLES[1]);
		this.add(reviewer_buttons, SidePanel.BUTTON_ROLES[2]);
		this.add(subprogram_buttons, SidePanel.BUTTON_ROLES[3]);
		this.add(program_buttons, SidePanel.BUTTON_ROLES[4]);
		this.setVisible(true);
	}
	
	/**
	 * Switches to the buttons available to the active role.
	 * @param role the active role.
	 */
	protected void updateButtons(final int role) {
		my_layout.show(this, SidePanel.BUTTON_ROLES[role]);
	}
	
	/**
	 * Appends credits to the sidebar container/card.
	 * @param container the container to append the credits to.
	 */
	private void addCredits(Container container) {
		container.add(Box.createVerticalStrut(150));
		container.add(new JLabel("Burning Penguins"));
		container.add(new JLabel("Conference Management"));
		container.add(Box.createVerticalStrut(15));
		container.add(new JLabel("Created by:"));
		container.add(new JLabel("Christopher Gelatt"));
		container.add(new JLabel("Sean Gray"));
		container.add(new JLabel("Tarl Hahn"));
		container.add(new JLabel("Rolando Sierra"));
	}
	
	/**
	 * Creates and maps the buttons for the user side panel.
	 * @return the container of buttons for the default user.
	 */
	private Container userMap() {
		Container user = new Container();
		user.setLayout(new BoxLayout(user, BoxLayout.Y_AXIS));
		
		user.add(new JLabel("Role: User"));
		user.add(Box.createVerticalStrut(15));
		
		Button2 login = new Button2("Login");
		login.setPattern(MainPanel.LAYOUT_LABELS[1], my_frame);
		user.add(login);
		
		this.addCredits(user);
		
		return user;
	}
	
	/**
	 * Creates and maps the buttons for the author role.
	 * @return the container of buttons for author actions.
	 */
	private Container authorMap() {
		Container author = new Container();
		author.setLayout(new BoxLayout(author, BoxLayout.Y_AXIS));
		
		author.add(new JLabel("Role: Author"));
		author.add(Box.createVerticalStrut(15));

		Button2 logout = new Button2("Logout");
		logout.setPattern(MainPanel.LAYOUT_LABELS[0], my_frame);
		author.add(logout);
		author.add(Box.createVerticalStrut(15));
		
		Button2 submit = new Button2("Submit");
		submit.setPattern(MainPanel.LAYOUT_LABELS[2], my_frame);
		author.add(submit);
		author.add(Box.createVerticalStrut(15));
		
		Button2 review = new Button2("Get Review");
		review.setPattern(MainPanel.LAYOUT_LABELS[5], my_frame);
		author.add(review);
		author.add(Box.createVerticalStrut(15));
		
		Button2 edit = new Button2("Edit Submission");
		edit.setPattern(MainPanel.LAYOUT_LABELS[6], my_frame);
		author.add(edit);

		this.addCredits(author);
		
		return author;
	}

	/**
	 * Maps the buttons to the reviewer side bar.
	 * @return the side bar for the reviewer.
	 */
	private Container reviewerMap() {
		Container reviewer = new Container();
		reviewer.setLayout(new BoxLayout(reviewer, BoxLayout.Y_AXIS));
		
		reviewer.add(new JLabel("Role: Reviewer"));
		reviewer.add(Box.createVerticalStrut(15));
		
		Button2 logout = new Button2("Logout");
		logout.setPattern(MainPanel.LAYOUT_LABELS[0], my_frame);
		reviewer.add(logout);
		reviewer.add(Box.createVerticalStrut(15));
		
		Button2 submit = new Button2("Submit Review");
		submit.setPattern(MainPanel.LAYOUT_LABELS[3], my_frame);
		reviewer.add(submit);
		
		this.addCredits(reviewer);
		
		return reviewer;
	}

	/**
	 * Maps the buttons for the subprogram chair sidebar.
	 * @return the container of buttons.
	 */
	private Container subprogMap() {
		Container subprog = new Container();
		subprog.setLayout(new BoxLayout(subprog, BoxLayout.Y_AXIS));

		subprog.add(new JLabel("Role: SubProgram Chair"));
		subprog.add(Box.createVerticalStrut(15));
		
		Button2 logout = new Button2("Logout");
		logout.setPattern(MainPanel.LAYOUT_LABELS[0], my_frame);
		subprog.add(logout);
		subprog.add(Box.createVerticalStrut(15));

		Button2 submit = new Button2("Submit Recommendation");
		submit.setPattern(MainPanel.LAYOUT_LABELS[4], my_frame);
		subprog.add(submit);
		subprog.add(Box.createVerticalStrut(15));

		Button2 assign = new Button2("Assign Paper");
		assign.setPattern(MainPanel.LAYOUT_LABELS[7], my_frame);
		subprog.add(assign);
		
		this.addCredits(subprog);
		
		return subprog;
	}

	/**
	 * Maps the program chair buttons to its container.
	 * @return the container with the program chair buttons.
	 */
	private Container chairMap() {
		Container chair = new Container();
		chair.setLayout(new BoxLayout(chair, BoxLayout.Y_AXIS));
		
		chair.add(new JLabel("Role: Program Chair"));
		chair.add(Box.createVerticalStrut(15));
		
		Button2 logout = new Button2("Logout");
		logout.setPattern(MainPanel.LAYOUT_LABELS[0], my_frame);
		chair.add(logout);
		chair.add(Box.createVerticalStrut(15));

		Button2 accept = new Button2("Accept Submission");
		accept.setPattern(MainPanel.LAYOUT_LABELS[8], my_frame);
		chair.add(accept);
		chair.add(Box.createVerticalStrut(15));
		
		Button2 designate = new Button2("Designate SubProgram Chairs");
		designate.setPattern(MainPanel.LAYOUT_LABELS[9], my_frame);
		chair.add(designate);
		chair.add(Box.createVerticalStrut(15));
		
		Button2 status = new Button2("View Status");
		status.setPattern(MainPanel.LAYOUT_LABELS[10], my_frame);
		chair.add(status);
		chair.add(Box.createVerticalStrut(15));
		
		Button2 view = new Button2("View Assignments");
		view.setPattern(MainPanel.LAYOUT_LABELS[11], my_frame);
		chair.add(view);
		
		this.addCredits(chair);
		
		return chair;
	}
	
	/**
	 * Maps the buttons to their containers.
	 */
	private void mapButtons() {
		user_buttons = userMap();
		author_buttons = authorMap();
		reviewer_buttons = reviewerMap();
		subprogram_buttons = subprogMap();
		program_buttons = chairMap();		
	}

}
